﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using HumanManagement.BusinessObjects;

namespace HumanManagement.DataAccess
{
	public class JobPositionManagementDA
	{

		#region ***** Init Methods ***** 
		public JobPositionManagementDA()
		{
		}
		#endregion

		#region ***** Get Methods ***** 
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public JobPositionManagement Populate(IDataReader myReader)
		{
			JobPositionManagement obj = new JobPositionManagement();
			obj.ID = (int) myReader["ID"];
			obj.PersonalProfileID = (int) myReader["PersonalProfileID"];
			obj.JobPositionDepartmentID = (int) myReader["JobPositionDepartmentID"];
			obj.EffectiveDate = (DateTime) myReader["EffectiveDate"];
			obj.ExpireDate = (DateTime) myReader["ExpireDate"];
			obj.LastDate = (DateTime) myReader["LastDate"];
			obj.LastMakerID = (int) myReader["LastMakerID"];
			obj.LastApproverID = (int) myReader["LastApproverID"];
			obj.ManagementStatus = (string) myReader["ManagementStatus"];
			return obj;
		}

		/// <summary>
		/// Get JobPositionManagement by id
		/// </summary>
		/// <param name="id">ID</param>
		/// <returns>JobPositionManagement</returns>
		public JobPositionManagement GetByID(int id, int PersonalProfileID)
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_JobPositionManagement_GetByID"
                                                                    , Data.CreateParameter("ID", id)
                                                                    , Data.CreateParameter("PersonalProfileID", PersonalProfileID)))
			{
				if (reader.Read())
				{
					return Populate(reader);
				}
				return null;
			}
		}

		/// <summary>
		/// Get all of JobPositionManagement
		/// </summary>
		/// <returns>List<<JobPositionManagement>></returns>
		public List<JobPositionManagement> GetList()
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_JobPositionManagement_Get"))
			{
				List<JobPositionManagement> list = new List<JobPositionManagement>();
				while (reader.Read())
				{
				list.Add(Populate(reader));
				}
				return list;
			}
		}

		/// <summary>
		/// Get DataSet of JobPositionManagement
		/// </summary>
		/// <returns>DataSet</returns>
		public DataSet GetDataSetOld()
		{
			return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure,"sproc_JobPositionManagement_Get");
		}

        public DataSet GetDataSet(int PersonalProfileID)
        {
            return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sproc_JobPositionManagement_Get"
                                            , Data.CreateParameter("PersonalProfileID", PersonalProfileID));
        }
		/// <summary>
		/// Get all of JobPositionManagement paged
		/// </summary>
		/// <param name="recperpage">record per page</param>
		/// <param name="pageindex">page index</param>
		/// <returns>List<<JobPositionManagement>></returns>
		public List<JobPositionManagement> GetListPaged(int recperpage, int pageindex)
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_JobPositionManagement_GetPaged"
							,Data.CreateParameter("recperpage", recperpage)
							,Data.CreateParameter("pageindex", pageindex)))
			{
				List<JobPositionManagement> list = new List<JobPositionManagement>();
				while (reader.Read())
				{
				list.Add(Populate(reader));
				}
				return list;
			}
		}

		/// <summary>
		/// Get DataSet of JobPositionManagement paged
		/// </summary>
		/// <param name="recperpage">record per page</param>
		/// <param name="pageindex">page index</param>
		/// <returns>DataSet</returns>
		public DataSet GetDataSetPaged(int recperpage, int pageindex)
		{
			return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure,"sproc_JobPositionManagement_GetPaged"
							,Data.CreateParameter("recperpage", recperpage)
							,Data.CreateParameter("pageindex", pageindex));
		}





		#endregion

		#region ***** Add Update Delete Methods ***** 
		/// <summary>
		/// Add a new JobPositionManagement within JobPositionManagement database table
		/// </summary>
		/// <param name="obj">JobPositionManagement</param>
		/// <returns>key of table</returns>
		public int Add(JobPositionManagement obj)
		{
			DbParameter parameterItemID = Data.CreateParameter("ID", obj.ID);
			parameterItemID.Direction = ParameterDirection.Output;
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_JobPositionManagement_Add"
							,parameterItemID
							,Data.CreateParameter("PersonalProfileID", obj.PersonalProfileID)
							,Data.CreateParameter("JobPositionDepartmentID", obj.JobPositionDepartmentID)
							,Data.CreateParameter("EffectiveDate", obj.EffectiveDate)
							,Data.CreateParameter("ExpireDate", obj.ExpireDate)
							,Data.CreateParameter("LastDate", obj.LastDate)
							,Data.CreateParameter("LastMakerID", obj.LastMakerID)
							,Data.CreateParameter("LastApproverID", obj.LastApproverID)
							,Data.CreateParameter("ManagementStatus", obj.ManagementStatus)
			);
			return (int)parameterItemID.Value;
		}

		/// <summary>
		/// updates the specified JobPositionManagement
		/// </summary>
		/// <param name="obj">JobPositionManagement</param>
		/// <returns></returns>
		public void Update(JobPositionManagement obj)
		{
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_JobPositionManagement_Update"
							,Data.CreateParameter("ID", obj.ID)
							,Data.CreateParameter("PersonalProfileID", obj.PersonalProfileID)
							,Data.CreateParameter("JobPositionDepartmentID", obj.JobPositionDepartmentID)
							,Data.CreateParameter("EffectiveDate", obj.EffectiveDate)
							,Data.CreateParameter("ExpireDate", obj.ExpireDate)
							,Data.CreateParameter("LastDate", obj.LastDate)
							,Data.CreateParameter("LastMakerID", obj.LastMakerID)
							,Data.CreateParameter("LastApproverID", obj.LastApproverID)
							,Data.CreateParameter("ManagementStatus", obj.ManagementStatus)
			);
		}

		/// <summary>
		/// Delete the specified JobPositionManagement
		/// </summary>
		/// <param name="id">ID</param>
		/// <returns></returns>
		public void Delete(int id)
		{
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_JobPositionManagement_Delete", Data.CreateParameter("ID", id));
		}
		#endregion
	}
}
